package com.xiaoleng;

import com.xiaoleng.entity.SmsInfo;
import com.xiaoleng.service.IMailService;
import com.xiaoleng.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;
import java.util.List;

@Configuration
@EnableScheduling
public class SaticScheduleTask {
    @Autowired
    private SmsService smsService;

    @Autowired
    private IMailService mailService;

    //3.添加定时任务
//    @Scheduled(cron = "0/10 * * * * ?")
    @Scheduled(cron = "*/5 * * * * ?")
    //或直接指定时间间隔，例如：5秒
    //@Scheduled(fixedRate=5000)
    private void configureTasks() {
        String oneSmsInfo = smsService.findOneSmsInfo();
//        mailService.sendSimpleMail("1113064623@qq.com", "早安", oneSmsInfo);
        mailService.sendSimpleMail("1113064623@qq.com", "早安", oneSmsInfo);
        System.err.println("执行静态定时任务时间: " + LocalDateTime.now());
    }
}
